import { Context } from 'egg'
import { EntityService, Auth } from '../core'

export default class UserService extends EntityService {
  auth: Auth
  constructor(ctx: Context) {
    super(ctx, 'User')
    this.auth = this.app.uow.auth
  }

  async create(user) {
    return this.auth.createUser(user)
  }

  async update(id, updates) {
    return this.auth.updateUser(id, updates)
  }

  async del(id) {
    return this.auth.deleteUser(id)
  }

  async sign(data) {
    return this.auth.sign(data)
  }

  async decode(accessToken) {
    return this.auth.decode(accessToken)
  }

  async verify(accessToken) {
    return this.auth.verify(accessToken)
  }

  async getSettings() {
    const { userId } = this.ctx.state.user
    return this.auth.getSettings(userId)
  }
}
